﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using Engine;
using System.IO;
using Engine.FileSystem;
using System.Diagnostics;
using Engine.MapSystem;

namespace Arcanea.MMORPGClient
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {

            if (Debugger.IsAttached)
            {
                Main2();
            }
            else
            {
                try
                {
                    Main2();
                }
                catch (Exception e)
                {
                    Log.FatalAsException(e.ToString());
                }
            }
        }

        static void Main2()
        {

            Log.DumpFileName = Path.Combine(Environment.CurrentDirectory, "Logs/Engine.log");
            Log.DumpToFile(string.Format("Game {0}\r\n", EngineVersionInformation.Version));

            if (!VirtualFileSystem.Init())
                return;

            EngineApp.ConfigName = Path.Combine(Environment.CurrentDirectory, "Configs\\Engine.config");

            EngineApp.Init(new ArcaneaEngineApp());
            EngineApp.Instance.WindowTitle = "Arcanea";

            EngineConsole.Init();

            EngineApp.Instance.Config.RegisterClassParameters(typeof(ArcaneaEngineApp));

            if (EngineApp.Instance.Create())
            {
                EngineApp.Instance.Run();
            }

            EngineApp.Shutdown();
            VirtualFileSystem.Shutdown();
        }
    } 
}
